package com.neulogistics.core.substation.infrastructure.persistence.repository;

import com.neulogistics.core.substation.domain.model.aggregate.Substation;
import com.neulogistics.core.substation.domain.repository.ISubstationRepository;
import com.neulogistics.core.substation.infrastructure.persistence.converter.SubstationEntityPOConverter;
import com.neulogistics.core.substation.infrastructure.persistence.orm.po.SubstationPO;
import com.neulogistics.core.substation.infrastructure.persistence.orm.service.ISubstationPOService;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class SubstationRepository implements ISubstationRepository {
    @Resource
    ISubstationPOService substationPOService;

    @Override
    public void save(Substation substation) {
        SubstationPO substationPO = SubstationEntityPOConverter.entityToPO(substation);
        substationPOService.saveOrUpdate(substationPO);
        substation.setSubstationId(substationPO.getSubstationId());
    }

    @Override
    public Substation findById(Integer id) {
        SubstationPO substationPO = substationPOService.getById(id);
        Substation substation = SubstationEntityPOConverter.POToEntity(substationPO);
        return substation;
    }

    @Override
    public void deleteById(Integer id) {
        substationPOService.removeById(id);
    }
}
